from keras.preprocessing.image import ImageDataGenerator
from keras import backend as K
from keras.datasets import mnist
from matplotlib import pyplot
K.set_image_data_format('channels_first')

(X_train,y_train),(X_test,y_test) = mnist.load_data()
X_train = X_train.reshape(X_train.shape[0],1,28,28)
X_test = X_train.reshape(X_test.shape[0],1,28,28)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
datagen = ImageDataGenerator(featurewise_center=True,featurewise_std_normalization=True,
            samplewise_center=True,samplewise_std_normalization=True)
datagen.fit(X_train)
for X_batch,y_batch, in datagen.flow(X_train,y_train,batch_size=9):
    for i in range(0,9):
        ax = pyplot.subplot(330+1+i)
        pyplot.tight_layout()
        ax.tick_params(axis='x',colors='white')
        ax.tick_params(axis='y',colors='white')
        pyplot.imshow(X_batch[i].reshape(28,28),cmap=pyplot.get_cmap('gray'))
pyplot.show()
